home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 4 / MacMania 4.toast / / Demo's / Igor Demo Pro / 1 PutContentsIn Igor Pro Folder / WaveMetrics Procedures / Image and Contour Plots / Autosize Images < prev    next >
Text File  |  1996-01-30  |  3KB  |  96 lines

  1. //    This package makes it easy to properly size images, especially photographs.
  2. //    It adds AutoSizeImage to the Macros menu.
  3. //
  4. //    In the dialog from AutoSizeImage:
  5. //    Choose Yes from Flip Vertical if you are displaying a photograph
  6. //    Set the multiplier to zero to let the package try to find a proper size
  7. //    or enter your own multiplier to force the image to be a particular size.
  8. //    The size in Points will be the size of the dimensions of the matrix
  9. //    times your multiplier. The size will be fixed if you enter your own
  10. //    multiplier but will be resizeable if you enter zero.
  11.  
  12. //    You might find it handy to call the DoAutoSizeImage function from your
  13. //    own code.
  14.  
  15. #pragma rtGlobals= 1
  16.  
  17. Macro AutoSizeImage(forceSize,flipVert)
  18.     Variable forceSize= NumVarOrDefault("root:Packages:WMAutoSizeImages:forceSizeSav",0)
  19.     Variable flipVert= NumVarOrDefault("root:Packages:WMAutoSizeImages:flipVertSav",1)+1
  20.     Prompt forceSize,"Enter multiplier for forced image size or zero to autosize"
  21.     Prompt flipVert,"Flip vertical (images)",Popup "Yes;No"
  22.     
  23.     DoAutoSizeImage(forceSize,flipVert-1)
  24. end
  25.  
  26. Function DoAutoSizeImage(forceSize,flipVert)
  27.     variable forceSize,flipVert
  28.     
  29.     if( (forceSize != 0) )
  30.         if( (forceSize<0.1) %| (forceSize>20) )
  31.             Abort "Unlikey value for forceSize; usually 0 or between .1 and 20"
  32.             return 0
  33.         endif
  34.     endif
  35.     String imagename= ImageNameList("", ";")
  36.     Variable p1= strsearch(imagename, ";", 0)
  37.     if( p1 <= 0 )
  38.         Abort "Graph contains no images"
  39.         return 0
  40.     endif
  41.  
  42.     // Remember input for next time
  43.     String dfSav= GetDataFolder(1);
  44.     NewDataFolder/O/S root:Packages
  45.     NewDataFolder/O/S WMAutoSizeImages
  46.     Variable/G forceSizeSav= forceSize
  47.     Variable/G flipVertSav= flipVert
  48.     SetDataFolder dfSav
  49.     
  50.      imagename= imagename[0,p1-1]
  51.     Wave w= ImageNameToWaveRef("",imagename)
  52.     Variable height= DimSize(w,1)
  53.     Variable width= DimSize(w,0)
  54.     do
  55.         if( forceSize )
  56.             height *= forceSize;
  57.             width *= forceSize;
  58.             break
  59.         endif
  60.         variable maxdim= max(height,width)
  61.         NewDataFolder/S tmpAutoSizeImage
  62.         Make/O sizes={20,50,100,200,600,1000,2000,10000}        // temp wavesused as lookup tables
  63.         Make/O scales={16,8,4,2,1,0.5,0.25,0.125}
  64.         Variable nsizes= numpnts(sizes),scale= 0,i= 0
  65.         do
  66.             if( maxdim < sizes[i] )
  67.                 scale= scales[i]
  68.                 break;
  69.             endif
  70.             i+=1
  71.         while(i<nsizes)
  72.         KillDataFolder :            // zap our two temp waves that were used as lookup tables
  73.         if( scale == 0 )
  74.             Abort "Image is bigger than planed for"
  75.             return 0
  76.         endif
  77.         width *= scale;
  78.         height *= scale;
  79.     while(0)
  80.  
  81.     String axname= ImageInfo("",imagename,0)
  82.     Variable p0= strsearch(axname, "YAXIS:", 0)
  83.     p0=  strsearch(axname, ":", p0)
  84.     p1=  strsearch(axname, ";", p0)
  85.     if( flipVert )
  86.         SetAxis/A $(axname[p0+1,p1-1])
  87.     else
  88.         SetAxis/A/R $(axname[p0+1,p1-1])
  89.     endif
  90.     ModifyGraph width=width,height=height
  91.     DoUpdate
  92.     if( forceSize==0 )
  93.         ModifyGraph width=0,height=0
  94.     endif
  95. end
  96.